package cn.psvmc.cxzapi.controller.customer;

import cn.psvmc.cxzapi.model.common.PageEntity;
import cn.psvmc.cxzapi.model.customer.TCustomerGoodsCollect;
import cn.psvmc.cxzapi.response.PageResult2;
import cn.psvmc.cxzapi.response.Result;
import cn.psvmc.cxzapi.response.ResultGenerator;
import cn.psvmc.cxzapi.service.customer.TCustomerGoodsCollectService;
import cn.psvmc.cxzapi.util.PageUtil;
import cn.psvmc.cxzapi.util.ToolUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 我的收藏
 *
 * @Author auto
 * @Date 2024-08-27
 */
@RestController
@RequestMapping("/mpapi/customer_collect")
public class TCustomerGoodsCollectController {

    @Resource
    private TCustomerGoodsCollectService tCustomerGoodsCollectService;

    /**
     * @Description 收藏
     * @Date 2024/8/27 21:45
     * @Author YWX
     * @Param [tCustomerGoodsCollect]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/add")
    public Result add(@RequestBody TCustomerGoodsCollect tCustomerGoodsCollect) {
        ToolUtils.validation(new Object[]{tCustomerGoodsCollect.getGoodsId(), "商品id", 1});
        tCustomerGoodsCollectService.add(tCustomerGoodsCollect);
        return ResultGenerator.genSuccessResult("收藏成功！");
    }

    /**
     * @Description 取消收藏
     * @Date 2024/8/27 21:46
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/delete")
    public Result delete(@RequestBody TCustomerGoodsCollect entity) {
        Integer id = entity.getGoodsId();
        ToolUtils.validation(new Object[]{id, "商品id", 1});
        tCustomerGoodsCollectService.delete(id);
        return ResultGenerator.genSuccessResult("取消收藏成功！");
    }

    /**
     * @Description 我的收藏列表
     * @Date 2024/8/27 21:50
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.PageResult2
     **/
    @PostMapping("/list")
    public PageResult2 list(@RequestBody PageEntity entity) {
        Page<TCustomerGoodsCollect> queryPage = new Page<>(entity.getPage(), entity.getSize());
        return PageUtil.getPageResult2(tCustomerGoodsCollectService.list(queryPage));
    }

    /**
     * @Description 商品是否收藏
     * @Date 2024/9/5 21:46
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/is_goods_collect")
    public Result isGoodsCollect(@RequestBody TCustomerGoodsCollect entity) {
        Integer id = entity.getGoodsId();
        ToolUtils.validation(new Object[]{id, "商品id", 1});
        return ResultGenerator.genSuccessResult("获取成功！", tCustomerGoodsCollectService.isGoodsCollect(id));
    }
}
